The present invention is directed to object-oriented programming systems, and more particularly to optimizing the representation of associations in object-oriented programming systems.
Conventional object-oriented programming systems often record the association between a particular object and another object or a data structure internal to the system. Frequently, however, the demographics (e.g., usage pattern) of such associations cannot be predicted with accuracy ahead of time. Whether a particular object participates in an association depends upon the activities of the applications hosted by the system.
An example of one conventional object-oriented programming system that uses associations is Sun Microsystems.TM. Java.TM. object-oriented programming language. Java and Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
Most implementations of the Java programming language associate a secondary structure with an object in the event that a synchronized method (i.e., a method whose invocation is synchronized on its receiver) is invoked on that object. This secondary structure is called a monitor and engages a variety of mechanisms in the Java.TM. runtime system and the native platform for the purpose of coordinating concurrent execution of synchronized methods. For efficiency reasons, the monitor is typically allocated for and associated with an object only if a synchronized method is invoked upon that object. Unfortunately, such a determination can only be made at the actual point of method invocation.
Two conventional approaches exist for recording associations. The first approach stores the association, which takes the form of a reference to the monitor, in a separate data structure, such as a hash table. This approach economizes the use of space because space in the hash table need not be allocated until actually required to record an association, but imposes a run-time penalty in the form of the time required to search the hash table for the location of the association.
The second approach alleviates this run-time penalty by storing the association in the header of the object in memory. The object header is an area of memory of fixed size that prefixes every object. Storing the association in the object header considerably increases the speed of retrieval of the association because the association is available directly from the object. However, given that the association demographics cannot be predicted ahead of time, a conservative approach would require that every object be provided with space for the storage of an association. This leads to a considerable waste of valuable memory space.
Therefore, a need exists for a way to record associations while alleviating the problems of the two conventional approaches.